define(function(require) {
	require("jquery");
	var appInfo = require('app/AppInfo');
	var c = require('app/utils/CommonUtils');
	var hc = require('app/utils/HttpClientUtils');
	var tip = require('app/utils/TipUtils');
	var dbu = require('app/utils/DBUtils');
	var WeixinUtils = require('app/utils/WeixinUtils');
	var UserInfoUtils = require('app/utils/UserInfoUtils');
	var win = window;
	var header_h = win.header_h;
	var action = {};
	action.WxLoginWin = function() {
		WeixinUtils.login(function(status, ret, accesstoken){
			
			if(status){
				//"0F2g5lsFyU_0lxM_F8Uz95pmBKC1GUAprZle3veGy0PS-XfcPfRxVCIqIp-n9kOM-6H8M_nBbgRVsmWKBBd-mo-1cPM21N1qpAdwb_ek2Wc"
//				{"openid":"oEKmV0oXmC7Ac_bkUlzv9wQehrOM","nickname":"侯晓宇","sex":1,"province":"北京","city":"海淀","country":"中国","headimgurl":"http://wx.qlogo.cn/mmopen/xLnlj0wXbc6tDHAQCGAfDvvPDcVBGeFfH9H3HmchyNOjoZCxD5RDUt3CZkek1QiaiazQiatYYW5SGXpNaLFWsrChicDsHa7EVMdb/0","privilege":[],"unionid":"o9SI3t5zIxt0rkk9_4w8AshIJcWI","status":true,"code":0} at CommonUtils.js : 97
				c.l(ret);
				c.l(accesstoken);
				
				var url = appInfo.serverbase + "/luyan/wxlogin";
				var body = {
					unionid: ret.unionid,
					accesstoken: accesstoken,
					openid: ret.openid,
					nickname: ret.nickname,
					headimgurl: ret.headimgurl
				};
				
				hc.post(url, body, function(resp){
					if(resp.status == "200"){
						c.l(resp.result);

						var user = {};
						user.uuid = resp.result.useruuid;
						user.wxUnionid = resp.result.unionid;
						user.tel = resp.result.tel;
						user.name = resp.result.name;
						user.wxHeadimgurl = resp.result.headimgurl;
						user.userType = resp.result.usertype;
						
						UserInfoUtils.saveUser(user);
						
						api.closeToWin({
						    name: 'root'
						});
					}else{
						alert("微信登陆失败，请重试！");
					}
														
				});
				
			}
		});	
	}
	action.openLoginWin = function() {
		var name = "LoginWin";
		api.openWin({
			name : name,
			url : './' + name + '.html',
			rect : {
				x : 0,
				y : 0,
				w : api.frameWidth,
				h : api.frameHeight - 0
			},
		});
	}
	action.openRegistWin = function() {
		var name = "RegistWin";
		api.openWin({
			name : name,
			url : './' + name + '.html',
			rect : {
				x : 0,
				y : 0,
				w : api.frameWidth,
				h : api.frameHeight
			},
		});
	}

	return action;
});
